from fastapi import FastAPI, HTTPException
import sqlite3

app = FastAPI()

# 数据库查询函数
@app.get("/get_price")
def query_price(keyword: str):
    # conn = sqlite3.connect('cloud_clip.db')  #
    # cursor = conn.cursor()
    # query = "SELECT price FROM products WHERE name LIKE ?"
    # cursor.execute(query, (f"%{keyword}%",))

    # result = cursor.fetchone()
    result = "test"
    # conn.close()
    if result:
        return {"price": result}
    else:
        return {"error": "Product not found"}

# API 路由

def get_price(keyword: str):
    result = query_price(keyword)
    if "error" in result:
        raise HTTPException(status_code=404, detail=result["error"])
    return result

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)